package com.tebiecloud.yunst.server.service.impl;

import com.tebiecloud.yunst.client.model.entity.YunBankCard;
import com.tebiecloud.yunst.server.mapper.YunBankCardMapper;
import com.tebiecloud.yunst.server.service.YunBankCardService;
import com.tebiecloud.common.mybatis.base.service.impl.BaseServiceImpl;
import com.tebiecloud.yunst.server.yunstservice.YunStService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 *  服务实现类
 * @author tebie
 * @date 2019-09-07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class YunBankCardServiceImpl extends BaseServiceImpl<YunBankCardMapper, YunBankCard> implements YunBankCardService {

    @Autowired
    YunStService yunStService;

    @Autowired
    YunBankCardMapper yunBankCardMapper;

    @Override
    public Map<String, String> applyBindBankCard(Long userId,String bizUserId, String phone, String cardNo, String bank, String type, String icon, String name, String identityNo) {
        Map<String,String> resultMap = yunStService.applyBindBankCard(bizUserId,phone,cardNo,name,identityNo);
        if(resultMap.get("status").equals("OK")){
            YunBankCard yunBankCard = new YunBankCard();
            yunBankCard.setUserId(userId);
            yunBankCard.setBizUserId(bizUserId);
            yunBankCard.setBank(bank);
            yunBankCard.setCardNo(cardNo);
            yunBankCard.setIcon(icon);
            yunBankCard.setIdentityNo(identityNo);
            yunBankCard.setName(name);
            yunBankCard.setType(type);
            yunBankCard.setPhone(phone);
            yunBankCard.setStatus(1);
            yunBankCardMapper.insert(yunBankCard);
        }
        return resultMap;
    }
}
